package org.xp.judgeplatform.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.xp.judgeplatform.pojo.entity.ProblemSetItem;
import org.xp.judgeplatform.pojo.vo.ProblemSetVO.ProblemSetItemVO;

import java.util.List;

@Mapper
public interface ProblemSetItemMapper extends BaseMapper<ProblemSetItem> {
    
    /**
     * 查询题目集中的题目列表（包含题目信息）
     */
    @Select("SELECT i.*, p.title as problem_title, p.difficulty as problem_difficulty, " +
            "p.category as problem_category " +
            "FROM problem_set_items i " +
            "LEFT JOIN problems p ON i.problem_id = p.id " +
            "WHERE i.set_id = #{setId} " +
            "ORDER BY i.sort_order ASC")
    List<ProblemSetItemVO> selectItemsWithProblemInfo(@Param("setId") Long setId);
    
    /**
     * 分页查询题目集中的题目列表
     */
    @Select("SELECT i.*, p.title as problem_title, p.difficulty as problem_difficulty, " +
            "p.category as problem_category " +
            "FROM problem_set_items i " +
            "LEFT JOIN problems p ON i.problem_id = p.id " +
            "WHERE i.set_id = #{setId} " +
            "ORDER BY i.sort_order ASC")
    IPage<ProblemSetItemVO> selectItemsWithProblemInfoPage(IPage<ProblemSetItemVO> page, 
                                                           @Param("setId") Long setId);
}